<html>
<head>
  <meta charset="UTF-8">
  <title>阶乘计算器</title>
</head>
<body>
<table>
  <tr>
    <td><input type="text" id="numId" ></td>
    <td><input type="button" value="阶乘" onclick="jiecheng()"></td>
    <td>= <span id="resultSpan"></span></td>
  </tr>
</table>

<script type="text/javascript">
  function jiecheng() {
    const n = parseInt(document.getElementById('numId').value, 10);
    if (n < 0) {
      alert("负数没有阶乘");
      document.getElementById('resultSpan').textContent = "";
      return;
    }
    let res = 1;
    if (n === 0) {
      res = 1;
    } else {
      for (let i = 1; i <= n; i++) {
        res *= i;
      }
    }
    document.getElementById('resultSpan').textContent = res;
  }
</script>
</body>
</html>